package com.wanda.exception;

import com.wanda.common.R;
import com.wanda.common.ResponseEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author sky
 * @date 2022-08-26
 */
@ControllerAdvice
public class ControllerHandlerException {

    @ResponseBody
    @ExceptionHandler(Appexception.class)
    public R appException(Appexception appexception,HttpServletRequest request){
        return new R(appexception.getCode(),appexception.getMessage(),null);
    }

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public R appException(Exception exception,HttpServletRequest request){
        exception.printStackTrace();
        return new R(ResponseEnum.SYSTEM_ERROR,null);
    }
}
